﻿using System;
using System.Data;
using VegetableSale.NET.Entities;
using VegetableSale.NET.Utils;
namespace VegetableSale.NET.Dao;

public class RefundMapper
{
    public List<Refund> getRefundList(QueryDTO queryDTO)
    {
        String sql = "";

        if (queryDTO.Keyword.Equals(""))
        {
            sql = "select * from refund;";
        }
        else
        {
            sql = "SELECT * FROM refund WHERE remark='" + queryDTO.Keyword + "';";
        }

        List<Refund> refunds = new List<Refund>();

        DataSet dateSet = MySqlHelper.GetDataSet(sql);
        DataTable dataTable = dateSet.Tables[0];

        foreach (DataRow row in dataTable.Rows)
        {
            uint id = (uint)row[0];
            int commid = (int)row[1];
            double rfmoney = (double)row[2];
            int rfnumber = (int)row[3];
            string remark = (string)row[4];
            DateTime reftime = (DateTime)row[5];

            Refund refund = new Refund(id, commid, rfmoney, rfnumber,remark,reftime);
            refunds.Add(refund);
        }
        return refunds;
    }

    public void addRefund(RefundAddQuery refundAddQuery)
    {
        double rfmoney = refundAddQuery.Rfnumber * refundAddQuery.Skmoney;
        string reftime = TimeTransferUtils.GetSqlServerTimeString();
        string sql = "INSERT INTO refund (commid,rfmoney,rfnumber,remark,reftime) VALUES (" + refundAddQuery.Commid +
                     "," + rfmoney + "," + refundAddQuery.Rfnumber + ",'" + refundAddQuery.Remark + "','" + reftime +
                     "')";

        MySqlHelper.ExecuteSql(sql);
    }

    
}

